package com.gykj.zhumulangma.common.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.gykj.zhumulangma.common.bean.SubscribeBean.AlbumConverter;
import com.ximalaya.ting.android.opensdk.model.album.Album;

import com.gykj.zhumulangma.common.bean.SubscribeBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "SUBSCRIBE_BEAN".
*/
public class SubscribeBeanDao extends AbstractDao<SubscribeBean, Long> {

    public static final String TABLENAME = "SUBSCRIBE_BEAN";

    /**
     * Properties of entity SubscribeBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property AlbumId = new Property(0, long.class, "albumId", true, "_id");
        public final static Property Album = new Property(1, String.class, "album", false, "ALBUM");
        public final static Property Datetime = new Property(2, long.class, "datetime", false, "DATETIME");
    }

    private final AlbumConverter albumConverter = new AlbumConverter();

    public SubscribeBeanDao(DaoConfig config) {
        super(config);
    }
    
    public SubscribeBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"SUBSCRIBE_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY NOT NULL ," + // 0: albumId
                "\"ALBUM\" TEXT," + // 1: album
                "\"DATETIME\" INTEGER NOT NULL );"); // 2: datetime
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SUBSCRIBE_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SubscribeBean entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getAlbumId());
 
        Album album = entity.getAlbum();
        if (album != null) {
            stmt.bindString(2, albumConverter.convertToDatabaseValue(album));
        }
        stmt.bindLong(3, entity.getDatetime());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SubscribeBean entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getAlbumId());
 
        Album album = entity.getAlbum();
        if (album != null) {
            stmt.bindString(2, albumConverter.convertToDatabaseValue(album));
        }
        stmt.bindLong(3, entity.getDatetime());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }    

    @Override
    public SubscribeBean readEntity(Cursor cursor, int offset) {
        SubscribeBean entity = new SubscribeBean( //
            cursor.getLong(offset + 0), // albumId
            cursor.isNull(offset + 1) ? null : albumConverter.convertToEntityProperty(cursor.getString(offset + 1)), // album
            cursor.getLong(offset + 2) // datetime
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SubscribeBean entity, int offset) {
        entity.setAlbumId(cursor.getLong(offset + 0));
        entity.setAlbum(cursor.isNull(offset + 1) ? null : albumConverter.convertToEntityProperty(cursor.getString(offset + 1)));
        entity.setDatetime(cursor.getLong(offset + 2));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(SubscribeBean entity, long rowId) {
        entity.setAlbumId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(SubscribeBean entity) {
        if(entity != null) {
            return entity.getAlbumId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SubscribeBean entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
